/**
 * Created by Administrator on 2017/5/9.
 */

//图片居中
/*
function zmnImgCenter(obj){
    obj.each(function(){
        var $this=$(this);
        var objHeight=$this.height();//图片高度
        var objWidth=$this.width();//图片宽度
        var parentHeight=$this.parent().height();//图片父容器高度
        var parentWidth=$this.parent().width();//图片父容器宽度
        console.log(parentWidth);
        console.log(parentHeight);
        var ratio=objHeight/objWidth;
        if(objHeight>parentHeight && objWidth>parentWidth){//当图片宽高都大于父容器宽高
            if(objHeight>objWidth) {//赋值宽高
                $this.width(parentWidth);
                $this.height(parentWidth*ratio);
            }
            else {
                $this.height(parentHeight);
                $this.width(parentHeight/ratio);
            }
            objHeight=$this.height();//重新获取宽高
            objWidth=$this.width();
            if(objHeight>objWidth) {
                $(this).css("top",(parentHeight-objHeight)/2);
                //定义top属性
            }
            else
            {
                //定义left属性
                $(this).css("left",(parentWidth-objWidth)/2);
            }
        }
        else{//当图片宽高小于父容器宽高
            if(objWidth>parentWidth){//当图片宽大于容器宽，小于时利用css text-align属性居中
                $(this).css("left",(parentWidth-objWidth)/2);
            }
            $(this).css("top",(parentHeight-objHeight)/2);
        }
    })
}*/
window.onload = function(){
    var n=0;
    var imgMIDELL = document.getElementsByClassName('photoA');
    var widthC = window.screen.width;
    var heightC = window.screen.height;
    for(n;n<imgMIDELL.length;n++){
        var img= imgMIDELL[n];
        Zoom(img,widthC,heightC/2);
    }
}
function Zoom(obj,width, height)
{ var img=new Image();
    img.src=obj.src;
    var scale=Math.max(width/img.width, height/img.height);
    var newWidth=img.width*scale;
    var newHeight=img.height*scale;
    var div=obj.parentNode;
    obj.width=newWidth;
    obj.height=newHeight;
    div.style.width=width+"px";
    div.style.height=height+"px";
    div.style.overflow="hidden";
    obj.style.marginLeft=(width-newWidth)/2+"px";
    obj.style.marginTop=(height-newHeight)/2+"px";
}

